* README 
* Replication files for
* "Optimal Debt Maturity and Firm Investment" by J. Jungherr and I. Schott
* Prepared: September 2020

* Notes:
* The authors used Matlab R2019b and Stata 15 to produce the results in the paper.
* Necessary Stata packages: estout, filelist, freduse, tsmktim 
* Downloading data directly to Stata via FRED requires a free username and password at http://fred.stlouisfed.org.
* Wharton Research Data Services (WRDS) was used in preparing this paper. This service and the data available thereon constitute valuable intellectual property and trade secrets of WRDS and/or its third-party suppliers.


The folder that contains this README.txt file also contains the following folders and subfolders:

- FIGURES
	- Figures_code
	- Figures_data
- TABLES
	- Tables_code
	- Tables_data
- MATLAB
	- Benchmark (model with long-term debt & short-term debt)
	- LTD_CE (counterfactual with long-term debt & short-term debt, without debt dilution and debt overhang)
	- LTD_freform (model with long-term debt & short-term debt, financial reform)
	- STD (short-term debt model)
	- STD_freform (short-term debt model, financial reform)
- EMPIRICAL
	- Data
		- Compustat (proprietary, must be provided by user)
		- FISD (proprietary, must be provided by user)




GENERAL OVERVIEW:

The folders FIGURES and TABLES contain all files which are necessary to replicate the figures and tables in the main text and the appendix. 
To replicate the tables, go to the subdirectory TABLES_CODE and open the Matlab code MASTER_Tables.m. The code uses empirical and simulated model data from the TABLES_DATA subdirectory.
To replicate the figures, go to the subdirectory FIGURES_CODE. There are two master files here. First, open the Matlab code MASTER_Figures.m. Then open the Stata code MASTER_Figures.do. The codes use empirical and simulated model data from the FIGURES_DATA subdirectory.

The Matlab code used to generate the model results is inside the MATLAB folder. Running the code updates the model output saved inside the subdirectories FIGURES_DATA and TABLES_DATA.
To run the code, open the file MASTER.m in the MATLAB folder. MASTER.m selects and runs the various model versions used throughout the paper. Expected computation times are listed below.

The empirical data sets in the TABLES_DATA and FIGURES_DATA subfolders are generated by combining different original data sources (e.g. Compustat, FISD). The codes to generate these empirical data sets are provided in the folder EMPIRICAL. The main Stata file is MASTER_data.do in the EMPIRICAL folder.
Note that Compustat and FISD are proprietary datasets. In FIGURES_DATA and TABLES_DATA, we therefore only provide highly aggregated data moments. The data provided in FIGURES_DATA and TABLES_DATA is sufficient to replicate all Figures and Tables in the paper. Documentation for Compustat is available at https://wrds-web.wharton.upenn.edu/wrds/support/Data. Documentation for FISD is included in the EMPIRICAL/DATA/FISD subdirectory.



DETAILED OVERVIEW 


FIGURES:

- Figure 2: Open MASTER_Figures.m in FIGURES_CODE using Matlab, adjust the working directory, and execute the code.
- Figure 3: Open MASTER_Figures.do in FIGURES_CODE using Stata, adjust the working directory, and execute the code.
- Figure 4: Open MASTER_Figures.do in FIGURES_CODE using Stata, adjust the working directory, and execute the code.
Appendix figures:
- Figure 5: Open MASTER_Figures.do in FIGURES_CODE using Stata, adjust the working directory, and execute the code.
- Figure 6: Open MASTER_Figures.do in FIGURES_CODE using Stata, adjust the working directory, and execute the code.



TABLES:

- Table 2: Open MASTER_Tables.m in TABLES_CODE using Matlab, adjust the working directory, and execute the code.
- Table 3: Open MASTER_Tables.m in TABLES_CODE using Matlab, adjust the working directory, and execute the code.
- Table 4: Open MASTER_Tables.m in TABLES_CODE using Matlab, adjust the working directory, and execute the code.
- Table 5: Open MASTER_Tables.m in TABLES_CODE using Matlab, adjust the working directory, and execute the code.
- Table 6: Open MASTER_Tables.m in TABLES_CODE using Matlab, adjust the working directory, and execute the code.
Appendix tables:
- Table 7: Open MASTER_Tables.m in TABLES_CODE using Matlab, adjust the working directory, and execute the code.



MATLAB CODES:

To replicate the model results using Matlab, follow these steps:

- Go to the MATLAB subdirectory and open MASTER.m in Matlab.
- Adjust the working directory as indicated
- The MASTER.m file can be used to execute the following models:
	- BENCHMARK model (model with long-term debt & short-term debt)
		- Files are located in the subdirectory "Benchmark"
		- Runtime is approximately 120 minutes. 
		- All files that update the Tables and Figures are saved automatically.
	- MODEL EXPERIMENTS
		- COUNTERFACTUAL model without debt dilution and debt overhang (LTD_CE)
			- Files are located in the subdirectory "LTD_CE"
			- Runtime is approximately 120 minutes. 
			- All files that update the Tables and Figures are saved automatically.
		- Short-term debt model (STD)
			- Files are located in the subdirectory "STD"
			- Runtime is approximately two minutes.
			- All files that update the Tables and Figures are saved automatically.
		- Short-term debt model with a financial reform (STD_freform)
			- Files are located in the subdirectory "STD_freform"
			- Identical to the STD model, except that parameter XI is lowered by 25%.
			- Runtime is approximately two minutes. 
			- All files that update the Tables and Figures are saved automatically.
		- BENCHMARK model with a financial reform (LTD_freform)
			- Files are located in the subdirectory "LTD_freform"
			- Identical to the BENCHMARK model, except that parameter XI is lowered by 25%.
			- Runtime is approximately 120 minutes. 
			- All files that update the Tables and Figures are saved automatically.	
		



EMPIRICAL DATA:

To generate from scratch the empirical data used throughout the paper, follow these steps:
(Note: The data used in the paper was downloaded in November 2019.)

- Go to the EMPIRICAL subdirectory and open MASTER_data.do in Stata.
- Adjust the working directory, as indicated.
- Necessary COMPUSTAT data (not provided):
	- Place the annual Compustat dataset into the folder EMPIRICAL/DATA/COMPUSTAT. The file should be named "CompustatY.dta"
	- Place the quarterly Compustat dataset into the folder EMPIRICAL/DATA/COMPUSTAT. The file should be named "CompustatQ.dta"
	- Place the Compustat Monthly Updates Credit Ratings file into the folder EMPIRICAL/DATA/COMPUSTAT. The file should be named "daily updates - ratings.dta"
- Necessary FISD data (not provided):
	- Place the "BOND ISSUES" dataset into the folder EMPIRICAL/DATA/FISD. The file should be named "bond_issues.dta"
	- Place the "BOND RATINGS" dataset into the folder EMPIRICAL/DATA/FISD. The file should be named "bond_ratings.dta"
	- Place the "BOND SPREADS" dataset into the folder EMPIRICAL/DATA/FISD. The file should be named "bond_spreads.dta"
- (1) MASTER_data.do first computes yields of US treasuries. The necessary data from the Federal Reserve Board is provided in the folder EMPIRICAL/DATA.
- (2) Next, MASTER_data.do imports FISD data from EMPIRICAL/DATA/FISD, computes bond-level credit spreads, and saves the data set "FISD_spreads.dta".
- (3) Next, MASTER_data.do imports credit ratings from the Compustat Monthly Updates file in EMPIRICAL/DATA/COMPUSTAT and merges this information with rating-specific credit spreads from FISD. The resulting data set is "Spreads.dta".
- The consumer price index from FRED is included in EMPIRICAL/DATA (CPI.dta). The file CPI.do in EMPIRICAL can be used to update this information.
- (4) Next, MASTER_data.do merges the annual and quarterly Compustat files. The resulting data set is "Compustat_DDDO.dta".
- (5) Next, MASTER_data.do uses "Compustat_DDDO.dta" to create the empirical firm panel. The resulting data set is "CS_tmp.dta".
- (6) Next, MASTER_data.do creates financial variables of interest. "CS_tmp.dta" is updated.
- (7) Next, MASTER_data.do performs some data cleaning. The resulting data set is "CS_panel.dta".
- (8)-(10) Now "CS_panel.dta" is used to compute the empirical moments stored in TABLES_DATA. CS_moments_xs.do computes cross-sectional moments. CS_moments_wi.do computes within-firm moments. Empirical correlations with size and age are computed in CS_data_corrs.do. 
- (11) Now "CS_panel.dta" is used to compute the empirical moments stored in FIGURES_DATA. To this end, CS_data_bins.do collapses the empirical firm panel by size and age quintiles.
- (12) Now simulated model data generated by Matlab is used to compute some of the model moments stored in TABLES_DATA. To this end, Model_corrs.do computes correlations with size and age in a simulated firm panel generated by the benchmark model with long-term debt and short-term debt. All remaining model moments in TABLES_DATA and FIGURES_DATA are computed directly in Matlab.
	
